package com.ruoyi.system.controller;


import com.ruoyi.system.domain.MealStatisticDTO;
import com.ruoyi.system.service.IMealStatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/meal-statistic")
public class MealStatisticController {

    @Autowired
    private IMealStatisticService imealStatisticService;

    @GetMapping
    public List<MealStatisticDTO> getMealStatistic(@RequestParam String day) {
        return imealStatisticService.getMealStatistic(day);
    }
}
//package com.ruoyi.system.controller;
//
//
//import com.ruoyi.common.core.domain.AjaxResult;
//import com.ruoyi.system.domain.MealStatisticDTO;
//import com.ruoyi.system.service.IMealStatisticService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//
//
//@RestController
//public class MealStatisticController {
//
//    private final IMealStatisticService iMealStatisticService;
//
//    @Autowired
//    public MealStatisticController(IMealStatisticService iMealStatisticService) {
//        this.iMealStatisticService = iMealStatisticService;
//    }
//
//    /**
//     * 获取指定日期的餐品统计信息
//     *
//     * @param date yyyy-mm-dd
//     * @return
//     */
//    @GetMapping("/meal-statistics")
//    public AjaxResult getMealStatistics(
//            @RequestParam(value = "date", required = true) String date) {
//        List<MealStatisticDTO> result = iMealStatisticService.getMealStatisticsByDate(date);
//
//        Map<String, Object> resultMap = new HashMap<>();
//
//        // 初始化默认值（使用 set 方式避免构造函数问题）
//        MealStatisticDTO defaultLunch = new MealStatisticDTO();
//        defaultLunch.setMealType("");
//        defaultLunch.setOrderCount(0);
//        defaultLunch.setVerifiedCount(0);
//        defaultLunch.setUnverifiedCount(0);
//        defaultLunch.setVerificationRate("0.00%");
//
//        MealStatisticDTO defaultDinner = new MealStatisticDTO();
//        defaultDinner.setMealType("");
//        defaultDinner.setOrderCount(0);
//        defaultDinner.setVerifiedCount(0);
//        defaultDinner.setUnverifiedCount(0);
//        defaultDinner.setVerificationRate("0.00%");
//
//        resultMap.put("lunch", defaultLunch);
//        resultMap.put("dinner", defaultDinner);
//
//        // 遍历结果，仅在匹配时更新
//        for (MealStatisticDTO mealStatisticDTO : result) {
//            if ("午餐".equals(mealStatisticDTO.getMealType())) {
//                resultMap.put("lunch", mealStatisticDTO);
//            }
//            if ("晚餐".equals(mealStatisticDTO.getMealType())) {
//                resultMap.put("dinner", mealStatisticDTO);
//            }
//        }
//
//        return AjaxResult.success(resultMap);
//    }
//}
